﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Pg.BioMedics.SDR.Client.Multimedia
{
    /// <summary>
    /// Contains logic for disposing temprorary files
    /// </summary>
    internal class DisposableFiles : IDisposable
    {
        #region Fields

        private IList<string> files = new List<string>();

        #endregion

        #region Destructor

        ~DisposableFiles()
        {
            Dispose();
        }

        #endregion

        #region Methods

        /// <summary>
        /// Adds a new file to the disposable fiels list
        /// </summary>
        /// <param name="file">file name</param>
        internal void Add(string file)
        {
            if (String.IsNullOrEmpty(file))
                return;
            else if (!File.Exists(file))
                return;
            else if (!this.files.Contains(file))
                this.files.Add(file);
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            foreach (string file in this.files)
                if (File.Exists(file))
                    File.Delete(file);
        }

        #endregion
    }
}